# Maintainer: Oleg Titov <oleg.titov@gmail.com>

pkgbase=zstd
pkgname=('zstd' 'libzstd' 'libzstd-devel')
pkgver=1.4.9
pkgrel=1
pkgdesc="Zstandard - Fast real-time compression algorithm"
arch=('i686' 'x86_64')
url='https://facebook.github.io/zstd/'
license=('BSD')
makedepends=('gcc' 'make' 'cmake')
source=("https://github.com/facebook/${pkgbase}/releases/download/v${pkgver}/${pkgbase}-${pkgver}.tar.gz")
sha256sums=('29ac74e19ea28659017361976240c4b5c5c24db3b89338731a6feb97c038d293')
options=(!libtool)

prepare() {
  cd "${srcdir}/${pkgbase}-${pkgver}"
}

build() {
  cd "${srcdir}/${pkgbase}-${pkgver}"

  cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    ../${pkgbase}-${pkgver}/build/cmake

  make install DESTDIR="${srcdir}/dest"
}

package_zstd() {
  groups=('libraries')
  depends=('gcc-libs' 'libzstd')

  cd "${srcdir}/${pkgbase}-${pkgver}"
  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/share/man ${pkgdir}/usr/share/man/
  rm -f ${pkgdir}/usr/bin/*.dll
  install -D -m644 "LICENSE" "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"
}

package_libzstd() {
  depends=('gcc-libs')

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
}

package_libzstd-devel() {
  groups=('development')
  options=('staticlibs')
  depends=("libzstd=${pkgver}")
  pkgdesc="zstd headers and libraries"
  
  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
